/* 
 * author Kate
 */
function validateFields(){
    var quantities=document.getElementsByName("quantity");
    var quantity;
    var id;
    for(var i=0;i<quantities.length;i++){
        quantity=quantities[i];
            
        id=quantity.id.split("_")[1];
        
        if(quantity.value=="" || quantity.value=="0"){
            alert("Quantity must be positive number and less than 1000000000"); 
            document.getElementById("price_"+id).innerHTML="";
            document.getElementById("total_price").value="";
            return false;
        }
             
        if(quantity.value.length>9){
            alert("Sorry,too many items in your cart.\nCan't proceed");
            document.getElementById("price_"+id).innerHTML="";
            document.getElementById("total_price").value="";
            return false;
        }
        if(!isNumber(quantity.value)){
            alert("Quantity must be positive number");
            document.getElementById("price_"+id).innerHTML="";
            document.getElementById("total_price").value="";
            return false;
        }
           
    }
    return true;
}

function isNumber(str){ 
    var reg = new RegExp("^[0-9]{0,10}$");
    return (reg.test(str));
}
    

